package org.akomantoso.core.data;

import java.io.IOException;

import org.akomantoso.core.io.Input;
import org.akomantoso.core.io.InputUtil;
import org.akomantoso.core.io.Output;
import org.akomantoso.core.io.OutputUtil;

/**
 * The complex type eolType is shared by eol and eop elements as being able to specify a position within the next word
 * in which the break can happen
 * 
 * <pre>
 * 	<xsd:complexType name="eolType">
 * 		<xsd:complexContent>
 * 			<xsd:extension base="markeropt">
 * 				<xsd:attribute name="breakat" type="xsd:integer" />
 * 			</xsd:extension>
 * 		</xsd:complexContent>
 * 	</xsd:complexType>
 * </pre>
 * 
 * @author <a href="mailto:jacques.militello@gmail.com">Jacques Militello</a>
 * 
 * @since http://www.akomantoso.org/1.0
 */
public abstract class EolType extends MarkerOpt {

	public static final String ATTRIBUTE_BREAKAT = "breakat";
	
	private Integer _breakat;

	public int getBreakat() {
		return _breakat;
	}

	public void setBreakat(int breakat) {
		_breakat = breakat;
	}
	
	/**
	 * @see org.akomantoso.core.data.MarkerOpt#writeExternal(org.akomantoso.core.io.Output)
	 */
	@Override
	public <T extends Output> void writeExternal(T out) throws IOException {
		if (_breakat != null) {
			OutputUtil.writeAttribute(out, ATTRIBUTE_BREAKAT, _breakat.toString());	
		}
		super.writeExternal(out);
	}

	/**
	 * @see org.akomantoso.core.data.CoreOptImpl#readExternal(org.akomantoso.core.io.Input)
	 */
	@Override
	public <T extends Input> void readExternal(T in) throws IOException {
		_breakat = InputUtil.readInteger(in.readAttribute(ATTRIBUTE_BREAKAT));
		super.readExternal(in);
	}
	
}